package com.stupro.cjlu.service;

import com.stupro.cjlu.bo.LoginStatusBO;
import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.manager.LoginStatusManager;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;

//基础的服务类实现
@Data
public class BaseService {

    //服务端技术 身份验证
    @Autowired
    private HttpSession session;
    @Autowired
    private LoginStatusManager loginStatusManager;

    private LoginStatusBO getLoginStatus() {
        return loginStatusManager.getLoginStatus(session);
    }

    //获取用户ID
    protected Integer getUserId() {
        return getLoginStatus().getUserId();
    }

    //获取成功标志的码 相关信息为成功 输入数据
    protected ResultVO result(Object data) {
        return new ResultVO(ResultVO.SUCCESS, "success", data);
    }

    //获取成功结果的码 自定义的相关信息 数据
    protected ResultVO result(Object data, String message) {
        return new ResultVO(ResultVO.SUCCESS, message, data);
    }

    //获取失败结果的码 相关信息 数据未输入
    protected ResultVO failedResult(String message) {
        return new ResultVO(ResultVO.FAIL, message, null);
    }

    //获取失败结果的码 相关信息 数据
    protected ResultVO failedResult(String message, Object data) {
        return new ResultVO(ResultVO.FAIL, message, data);
    }

}
